﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:offer_user
	/// </summary>
	public partial class offer_user
	{
		public offer_user()
		{}
		#region  Method
        public int DeleteOffers(string uid)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@uid", SqlDbType.VarChar,200)
};
            parameters[0].Value = uid;

            DbHelperSQL.RunProcedure("[dbo].[P_userofferdeletes]", parameters, out rowsAffected);
            return rowsAffected;

        }
        public int UpdateOfferStatus(string uid, int st)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@uid", SqlDbType.VarChar,200),
                    new SqlParameter("@sta",SqlDbType.Int,4)
};
            parameters[0].Value = uid;
            parameters[1].Value = st;
            DbHelperSQL.RunProcedure("[dbo].[P_useroffers]", parameters, out rowsAffected);
            return rowsAffected;

        }
        public DataSet PageUserRewardOffer(int atid, int startid, int pagesize, out int count,out int wcount)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@atid", SqlDbType.Int,4),
                    new SqlParameter("@startIndex", SqlDbType.Int,4),
                    new SqlParameter("@endIndex", SqlDbType.Int,4),
                    new SqlParameter("@count", SqlDbType.Int,4),
                    new SqlParameter("@wcount", SqlDbType.Int,4),
};
            parameters[3].Direction = ParameterDirection.Output;
            parameters[4].Direction = ParameterDirection.Output;
            parameters[0].Value = atid;
            parameters[1].Value = startid;
            parameters[2].Value = startid + pagesize - 1;
            DataSet ds = DbHelperSQL.RunProcedure("[dbo].[P_PageRewardOfferCheck]", parameters, "ds");
            count = int.Parse(parameters[3].Value.ToString());
            wcount = int.Parse(parameters[4].Value.ToString());
            return ds;
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("oid", "offer_user"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int oid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4)
};
			parameters[0].Value = oid;

			int result= DbHelperSQL.RunProcedure("offer_user_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.offer_user model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4),
					new SqlParameter("@rbh", SqlDbType.Char,8),
					new SqlParameter("@job", SqlDbType.VarChar,20),
					new SqlParameter("@payid", SqlDbType.VarChar,20),
					new SqlParameter("@unit", SqlDbType.VarChar,50),
					new SqlParameter("@offername", SqlDbType.VarChar,20),
					new SqlParameter("@offerID", SqlDbType.VarChar,18),
					new SqlParameter("@phone", SqlDbType.Char,11),
					new SqlParameter("@email", SqlDbType.VarChar,30),
					new SqlParameter("@ismy", SqlDbType.Bit,1)
					};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.rbh;
			parameters[2].Value = model.job;
			parameters[3].Value = model.payid;
			parameters[4].Value = model.unit;
			parameters[5].Value = model.offername;
			parameters[6].Value = model.offerID;
			parameters[7].Value = model.phone;
			parameters[8].Value = model.email;
			parameters[9].Value = model.ismy;			
			DbHelperSQL.RunProcedure("offer_user_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.offer_user model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4),
					new SqlParameter("@rbh", SqlDbType.Char,4),
					new SqlParameter("@job", SqlDbType.VarChar,20),
					new SqlParameter("@payid", SqlDbType.Int,4),
					new SqlParameter("@unit", SqlDbType.VarChar,50),
					new SqlParameter("@offername", SqlDbType.VarChar,20),
					new SqlParameter("@offerID", SqlDbType.VarChar,18),
					new SqlParameter("@phone", SqlDbType.Char,11),
					new SqlParameter("@email", SqlDbType.VarChar,30),
					new SqlParameter("@ismy", SqlDbType.Bit,1),
					new SqlParameter("@offertime", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.Int,4)};
			parameters[0].Value = model.oid;
			parameters[1].Value = model.rbh;
			parameters[2].Value = model.job;
			parameters[3].Value = model.payid;
			parameters[4].Value = model.unit;
			parameters[5].Value = model.offername;
			parameters[6].Value = model.offerID;
			parameters[7].Value = model.phone;
			parameters[8].Value = model.email;
			parameters[9].Value = model.ismy;
			parameters[10].Value = model.offertime;
			parameters[11].Value = model.status;

			DbHelperSQL.RunProcedure("offer_user_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int oid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4)
};
			parameters[0].Value = oid;

			DbHelperSQL.RunProcedure("offer_user_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string oidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from offer_user ");
			strSql.Append(" where oid in ("+oidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.offer_user GetModel(int oid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4)
};
			parameters[0].Value = oid;

			lcmyjobs.Model.offer_user model=new lcmyjobs.Model.offer_user();
			//DataSet ds= DbHelperSQL.RunProcedure("offer_user_GetModel",parameters,"ds");
            // add by liuhui 上述存储过程offer_user_GetModel未实现
            StringBuilder strSql=new StringBuilder();
			strSql.Append("select * FROM offer_user");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["oid"]!=null && ds.Tables[0].Rows[0]["oid"].ToString()!="")
				{
					model.oid=int.Parse(ds.Tables[0].Rows[0]["oid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["rbh"]!=null && ds.Tables[0].Rows[0]["rbh"].ToString()!="")
				{
					model.rbh=ds.Tables[0].Rows[0]["rbh"].ToString();
				}
				if(ds.Tables[0].Rows[0]["job"]!=null && ds.Tables[0].Rows[0]["job"].ToString()!="")
				{
					model.job=ds.Tables[0].Rows[0]["job"].ToString();
				}
				if(ds.Tables[0].Rows[0]["payid"]!=null && ds.Tables[0].Rows[0]["payid"].ToString()!="")
				{
					model.payid=ds.Tables[0].Rows[0]["payid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["unit"]!=null && ds.Tables[0].Rows[0]["unit"].ToString()!="")
				{
					model.unit=ds.Tables[0].Rows[0]["unit"].ToString();
				}
				if(ds.Tables[0].Rows[0]["offername"]!=null && ds.Tables[0].Rows[0]["offername"].ToString()!="")
				{
					model.offername=ds.Tables[0].Rows[0]["offername"].ToString();
				}
				if(ds.Tables[0].Rows[0]["offerID"]!=null && ds.Tables[0].Rows[0]["offerID"].ToString()!="")
				{
					model.offerID=ds.Tables[0].Rows[0]["offerID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["phone"]!=null && ds.Tables[0].Rows[0]["phone"].ToString()!="")
				{
					model.phone=ds.Tables[0].Rows[0]["phone"].ToString();
				}
				if(ds.Tables[0].Rows[0]["email"]!=null && ds.Tables[0].Rows[0]["email"].ToString()!="")
				{
					model.email=ds.Tables[0].Rows[0]["email"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ismy"]!=null && ds.Tables[0].Rows[0]["ismy"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["ismy"].ToString()=="1")||(ds.Tables[0].Rows[0]["ismy"].ToString().ToLower()=="true"))
					{
						model.ismy=true;
					}
					else
					{
						model.ismy=false;
					}
				}
				if(ds.Tables[0].Rows[0]["offertime"]!=null && ds.Tables[0].Rows[0]["offertime"].ToString()!="")
				{
					model.offertime=DateTime.Parse(ds.Tables[0].Rows[0]["offertime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["status"]!=null && ds.Tables[0].Rows[0]["status"].ToString()!="")
				{
					model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select oid,rbh,job,payid,unit,offername,offerID,phone,email,ismy,offertime,status ");
			strSql.Append(" FROM offer_user ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" oid,rbh,job,payid,unit,offername,offerID,phone,email,ismy,offertime,status ");
			strSql.Append(" FROM offer_user ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "offer_user";
			parameters[1].Value = "oid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

